package top.suven.base.http.admin.old.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.suven.base.core.mybatis.PageData;
import top.suven.base.http.admin.old.dao.SysAdminDao;
import top.suven.base.http.admin.old.model.SysAdmin;
import top.suven.base.http.admin.old.service.SysAdminService;
import top.suven.base.http.admin.old.vo.response.SysAdminResponseVo;
import top.suven.base.http.enums.EnableStatusEnum;
import top.suven.base.util.utilize.BeanUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**   
 * @Title: SysAdminService.java
 * @Description: 管理员信息的业务处理服务类
 * @author lixiangling
 * @date   2018/08/07 14:49:17
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
@Component("sysAdminService")
public class SysAdminServiceImpl implements SysAdminService {
    private final static Logger logger = LoggerFactory.getLogger(SysAdminServiceImpl.class);
    @Autowired
    private SysAdminDao sysAdminDao;
    /**
     * @Title: 获取管理员信息分页信息
     * @Description:
     * @param sysAdmin @{Link SysAdmin}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/07 14:49:17
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public PageData<SysAdminResponseVo> getSysAdminPage(SysAdmin sysAdmin, int start, int pageSize){
        int count = sysAdminDao.countEntity(sysAdmin);
        if(count == 0){
            return new PageData<SysAdminResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<SysAdmin> sysAdminList = sysAdminDao.findPageEntity(sysAdmin, start, pageSize);
        if(sysAdminList == null || sysAdminList.isEmpty()){
            return new PageData<SysAdminResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<SysAdminResponseVo> sysAdminResponseList = sysAdminList.stream().map(sysAdminResponse -> {
            SysAdminResponseVo sysAdminResponseVo = new SysAdminResponseVo();
            BeanUtil.copyProperties(sysAdminResponse, sysAdminResponseVo);
            return sysAdminResponseVo;
        }).collect(Collectors.toList());
        return new PageData<SysAdminResponseVo>(sysAdminResponseList,count);
    }

    @Override
    public List<SysAdmin> getSysAdminList(SysAdmin sysAdmin) {
        return sysAdminDao.findEntity(sysAdmin);
    }

    /**
     * @Title: 新增管理员信息信息
     * @Description:
     * @param sysAdmin @{Link SysAdmin}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/07 14:49:17
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void addSysAdmin(SysAdmin sysAdmin){
        sysAdminDao.createEntity(sysAdmin);
    }
    /**
    * @Title: 修改管理员信息信息
    * @Description:
    * @param sysAdmin @{Link SysAdmin}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/07 14:49:17
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void updSysAdmin(SysAdmin sysAdmin){
        sysAdminDao.updateEntity(sysAdmin);
    }
   /**
    * @Title: 获取管理员信息信息
    * @Description:
    * @param adminCode @{Link String}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/07 14:49:17
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public SysAdmin getSysAdmin(String adminCode){
        SysAdmin sysAdmin = new SysAdmin();
        sysAdmin.setAdminCode(adminCode);
        return sysAdminDao.retrieveEntity(sysAdmin);
    }
    /**
     * @Title: 删除管理员信息信息
     * @Description:
     * @param ids @{Link Long[]}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/07 14:49:17
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void del(Long[] ids){
        sysAdminDao.del(Arrays.asList(ids));
    }
   /**
    * @Title: 启用管理员信息信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/07 14:49:17
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOn(Long[] ids){
        sysAdminDao.updateEnableStatus(EnableStatusEnum.ENABLE.getIndexStr(), Arrays.asList(ids));
    }
   /**
    * @Title: 禁用管理员信息信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/07 14:49:17
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOff(Long[] ids){
        sysAdminDao.updateEnableStatus(EnableStatusEnum.DISABLE.getIndexStr(), Arrays.asList(ids));
    }
}